<?php

namespace AppBundle\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use AppBundle\Util\Crypt\CryptUtil;

/**
 * Description of DecryptCommand
 *
 * @author yihao
 */
class DecryptCommand extends Command
{
    
    protected function configure()
    {
        $this
                ->setName('app:decrypt')
                ->setDescription('Decrypt encrypted string.')
                ->setDefinition(array(
                    new InputArgument('enc', InputArgument::REQUIRED, 'The encrypted string to decrypt'),
                ))
                ->setHelp(<<<EOT
The <info>app:decrypt</info> command decrypt a encrypted string.

You must alternatively specify the encrypted string to decrypt as the first argument:

  <info>php bin/console app:decrypt enc</info>

EOT
                );
    }
    
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $enc = $input->getArgument('enc');
        
        $result = CryptUtil::decrypt($enc);
        
        $output->writeln('Decrypt result: ' . $result);
    }
    
}
